<?php

require_once 'Core/Db/Table/Abstract.php';
require_once 'Core/Db/Table/Row/Abstract.php';
require_once 'Core/Db/Table/Rowset/Abstract.php';

class Nld_Models_News_Entry_Row extends Core_Db_Table_Row_Abstract
{
	public function save()
	{
		$this->slug 	= $this->getSlug();
		return parent::save();
	}
  public function getSlug()
  {
    $slug 		= $this->slug;
    $slug 		= strtolower(empty($slug) ? Core_Helper_String::url_title($this->title) : $slug);
    $where 		= ' AND `id` <> "' . intval($this->id) . '"';
		
		$entries 	= $this->getTable()->fetchAll('`slug` LIKE "' . $slug . '%"' . $where)
									->getRows('slug','id');
    while(array_key_exists($slug, $entries))
			$slug = Core_Helper_String::increment_string($slug, '-');

    return $slug;
  }
}